<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <filters :data-list="bigList" @changeData="changeData" />
        <el-table border :data="pageList">
          <el-table-column label="姓名" prop="username" />
          <el-table-column label="工号" prop="workNumber" />
          <el-table-column label="手机" prop="mobile" />
          <el-table-column label="部门" prop="departmentName" />
          <el-table-column
            v-for="(day, index) in dateList"
            :key="index"
            width="120"
            :label="day.toString()"
          >
            <template #default="{row}">
              {{ row.attendanceRecord[index].adtStatu | adtStatu }}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :total="filterList.length" @current-change="currentChange" />
      </el-card>
    </div>
  </div>
</template>

<script>
import { getAttendancesListMock } from '@/api/attendances'
import attendanceEnum from '@/api/constant/attendance'
import filters from './components/filters.vue'
export default {
  components: { filters },
  filters: {
    adtStatu(oldVal) {
      const res = attendanceEnum.holidayType.find(item => Number(item.id) === Number(oldVal))
      return res ? res.value : ''
    }
  },
  data() {
    return {
      bigList: [],
      filterList: [],
      currentPage: 1,
      pageSise: 10
    }
  },
  computed: {
    dateList() {
      return this.bigList[0] ? this.bigList[0].attendanceRecord.map(record => record.day) : []
    },
    pageList() {
      const end = this.currentPage * this.pageSise
      const start = end - this.pageSise
      return this.filterList.slice(start, end)
    }
  },
  async created() {
    this.bigList = await getAttendancesListMock()
    this.filterList = [...this.bigList]
    console.log(this.bigList)
  },
  methods: {
    changeData(newData) {
      this.filterList = [...newData]
    },
    currentChange(newPage) {
      this.currentPage = newPage
    }
  }
}
</script>

<style>

</style>
